package leeon.kaixin.wap.models;

import java.io.Serializable;

import leeon.mobile.BBSBrowser.utils.HTMLUtil;

public class Status implements Serializable {
	
	public static Status newInstance(String htmlDiv) {
		if (htmlDiv == null || htmlDiv.length() == 0) return null;
		Status s;
		if (htmlDiv.indexOf("转帖给大家：") != -1) {
			s = new StatusRepaste();
		} else if (htmlDiv.indexOf("上传了") != -1) {
			s = new StatusPic();
		} else {
			s = new Status();
		}
		s.parseHtml(htmlDiv);
		return s;
	}
	
	private static final long serialVersionUID = -3871919485734148572L;

	private String uid;
	
	private String uname;
	
	private String date;
	
	private String content;
		
	private void parseHtml(String htmlDiv) {
		parseUserHtml(htmlDiv);
		parseDateHtml(htmlDiv);
		//<a开头去掉 名字部分，直到date部分
		//否则全部取出，直到date部分
		if (htmlDiv.startsWith("<a"))
			parseContentHtml(HTMLUtil.findStrRegex(htmlDiv, "</a[^>]*>", "<div><font color=\"#999999\">"));
		else
			parseContentHtml(HTMLUtil.findStr(htmlDiv, "", "<div><font color=\"#999999\">"));
	}
	
	protected void parseContentHtml(String htmlDiv) {
		content = htmlDiv;
	}
	
	private void parseUserHtml(String htmlDiv) {
		//<a href="/home/?uid=5803553&amp;verify=2538938_2538938_1300780229_5718888b3b232b542fa66636dfb731fe_kx&amp;url=%2Fhome%2Fnews.php%3Fuid%3D2538938%26verify%3D2538938_2538938_1300779905_3029b0a25002d5e2bae7625f22f326cb_kx">闫敏</a>
		uid = HTMLUtil.findStr(htmlDiv, "/home/?uid=", "&amp");
		//uname = HTMLUtil.findStr(htmlDiv, ">", "</a>");
		uname = HTMLUtil.findStrBeforeTag(htmlDiv, "</a", ">", "</a");
	}
	
	private void parseDateHtml(String htmlDiv) {
		//<div><font color="#999999">今天 14:47</font></div>
		date = HTMLUtil.findStr(htmlDiv, "<div><font color=\"#999999\">", "</font>");
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public StatusType getType() {
		return StatusType.通用;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	
	
}
